  'use strict';
    import Base from './base.js';
    //美易通信息、文章、通信类控制器请求方法
    module.exports = class extends Base {
    //请求获取客户的联系记录
    async getguestcontactlistAction() {
      let guest_id = this.get('guest_id');
      let page = this.get('page');
      let size = this.get('size');
      let nowpage = page * size;
      let info = await this.model().query(' SELECT au.name,gc.time,gc.type,gc.content FROM `think_or_guest_contact` gc LEFT JOIN `think_or_app_user` au ON gc.userid = au.id WHERE gc.guestid = ' + guest_id + ' ORDER BY gc.time desc limit '+nowpage+','+size+' ');
      return think.isEmpty(info) ? this.json({ 'code': "200", 'msg': "暂无联系记录...", 'data': '' }) : this.json({ 'code': "100", 'msg': "success...", 'data': info });
    }
    //请求获取网络短信模板的总分类
    async getmessagelistAction(){
      let info = await this.model().query(' SELECT * FROM `think_message_classify` WHERE pid = 0 ');
      if(think.isEmpty(info)){
        return this.json({'code':"200",'msg':"没有找到数据...",'data':''});  
      }else{
        return this.json({'code':"100",'msg':"success...",'data':info});
      }
    }
    //请求获取网络短信模板二级分类
    async getmessagelistsecondAction(){
      let id = this.get('id');
      let info = await this.model().query(' SELECT * FROM `think_message_classify` WHERE pid = '+id+' ');
      if(think.isEmpty(info)){
        return this.json({'code':"200",'msg':"没有找到数据...",'data':''});  
      }else{
        return this.json({'code':"100",'msg':"success...",'data':info});
      }
      
    }
    //请求获取分类下的短信列表
    async getclassmessageAction(){
      let id = this.get('id');
      let info = await this.model().query(' SELECT * FROM `think_message_demo` WHERE pid = '+id+' ');
      if(think.isEmpty(info)){
        return this.json({'code':"200",'msg':"没有找到数据...",'data':''});  
      }else{
        return this.json({'code':"100",'msg':"success...",'data':info});  
      }
    }
    //请求获取我的自定义短信模板分类
    async getmessagelistmyAction(){
      let user_id = this.get('user_id');
      let info = await this.model().query(' SELECT * FROM `think_message_classify_my` WHERE userid = '+user_id+' ');
      if(think.isEmpty(info)){
        return this.json({'code':"200",'msg':"没有找到数据...",'data':''});  
      }else{
        return this.json({'code':"100",'msg':"success...",'data':info});  
      }
    }
    //请求添加我的模板分类
    async postaddclassifymyAction(){
      let post_info = this.post('post_info');
      let addinfo = JSON.parse(post_info);
      addinfo['time'] = Math.round(Date.now()/1000);
      let info = await this.model('message_classify_my').add(addinfo);
      if(think.isEmpty(info)){
        return this.json({'code':"200",'msg':"添加失败...",'data':''});  
      }else{
        return this.json({'code':"100",'msg':"添加成功...",'data':info});  
      }
    }
    //请求获取我的分类下的短信模板
    async getmyclassmessageAction(){
      let id = this.get('id');
      let info = await this.model().query(' SELECT * FROM `think_message_mydemo` WHERE pid = '+id+' ');
      if(think.isEmpty(info)){
        return this.json({'code':"200",'msg':"没有找到数据...",'data':''});  
      }else{
        return this.json({'code':"100",'msg':"success...",'data':info});  
      }
    }
    //请求提交并添加我的短信模板
    async postaddmydemoAction(){
      let post_info = this.post('post_info');
      let addinfo = JSON.parse(post_info);
      addinfo['time'] = Math.round(Date.now()/1000);
      let info = await this.model('message_mydemo').add(addinfo);
      if(think.isEmpty(info)){
        return this.json({'code':"200",'msg':"添加失败...",'data':''});  
      }else{
        return this.json({'code':"100",'msg':"添加成功...",'data':info});  
      }
    }
    //请求并更新我的短信模板
    async postupmydemoAction(){
      let id = this.post('id');
      let content = this.post('content');
      let res = this.model('message_mydemo').where({id:id}).update({content:content});
      return think.isEmpty(res) ? this.json({ 'code': "200", 'msg': "更新失败...", 'data': '' }) : this.json({ 'code': "100", 'msg': "更新成功...", 'data':'' });
    }
    //请求删除我的短信模板
    async postdeletemydemoAction(){
      let id = this.post('id');
      let res = this.model('message_mydemo').where({id:id}).delete();
      return think.isEmpty(res) ? this.json({ 'code': "200", 'msg': "删除失败...", 'data': '' }) : this.json({ 'code': "100", 'msg': "删除成功...", 'data':'' });
    }
    //请求编辑更新我的分类
    async postupmyclassifyAction(){
      let id = this.post('id');
      let title = this.post('title');
      let res = this.model('message_classify_my').where({id:id}).update({title:title});
      return think.isEmpty(res) ? this.json({ 'code': "200", 'msg': "更新失败...", 'data': '' }) : this.json({ 'code': "100", 'msg': "更新成功...", 'data':'' });
    }
    //请求删除我的短信模板分类
    async postdeletemyclassifyAction(){
      let id = this.post('id');
      let res = this.model('message_classify_my').where({id:id}).delete();
      let res1 = this.model('message_mydemo').where({pid:id}).delete();
      return think.isEmpty(res) ? this.json({ 'code': "200", 'msg': "更新失败...", 'data': '' }) : this.json({ 'code': "100", 'msg': "更新成功...", 'data':'' });
    }
    //请求保存对客户的联系记录
    async postaddguestcontactAction() {
      let post_info = this.post('post_info');
      let addinfo = JSON.parse(post_info);
      addinfo['time'] = Math.round(Date.now() / 1000);
      let info = await this.model('or_guest_contact').add(addinfo);
      return think.isEmpty(info) ? this.json({ 'code': "200", 'msg': "添加失败...", 'data': '' }) : this.json({ 'code': "100", 'msg': "添加成功...", 'data': info });
    }

    //bottom
  };